﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class guoguan_3dpls : System.Web.UI.Page
{
    protected string kjTime = "";
    protected string[] kjNo = null;
    protected string qs, dltBlue1, dltBlue2, ljMoney, qiShu, lotteryType, rule1, rule2, lotteryTypeName, week = "";
    protected string oneCount, twoCount,oneMoney, twoMoney, jiangChi, winMoney, sumWinMoney, sumMoney ,mywinMoney, mysumMoney = "0";
    protected int myoneCount, mythreeCount = 0;
    protected decimal jiangCZ = 0;
    protected Model.LotteryQs lotteryQs = null;
    protected List<Model.LotteryChipped> userBuy = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        lotteryType = Request["lotteryType"] ?? "1";
        if (!IsPostBack)
        {
            string sql = "select top 1 * from LotteryAnnouncement where LotteryType=" + lotteryType + " order by addtime desc";
            lotteryQs = BLL.LotteryQs.NewsTopOne(sql);
            qsddl.Items.Insert(0, new ListItem(lotteryQs.Lotteryqs.ToString() + "期", "0"));
            for (int i = 1; i <= 9; i++)
            {
                qsddl.Items.Insert(i, new ListItem((Convert.ToUInt32(lotteryQs.Lotteryqs) - i).ToString() + "期", i.ToString()));
            }
            qiShu = lotteryQs.Lotteryqs.ToString() + "期";
            //r1.Checked = true;
            bindlotteryTypeName();
            bindDate();
        }

    }
    protected void qsddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (qsddl.SelectedIndex == 0)
        {
            string sql = "select top 1 * from LotteryQs where LotteryType=" + lotteryType;
            lotteryQs = BLL.LotteryQs.NewsTopOne(sql);
            qiShu = lotteryQs.Lotteryqs.ToString() + "期";
        }
        qiShu = qsddl.SelectedItem.Text;
        bindlotteryTypeName();
        bindDate();
    }
    private void bindDate()
    {
        decimal jc = 0;
        qs = qsddl.SelectedItem.Text.Trim('期');
        //1；双色球；2；大乐透；3；排列三；4；排列五；5；福彩3D；6；七星彩；7；七乐彩；
        string sql = string.Format("SELECT top 1 * FROM LotteryAnnouncement WHERE LotteryType={0} and LotteryQS='{1}'", lotteryType, qs);
        Model.LotteryAnnouncement la = BLL.LotteryAnnouncement.GetModelBySql(sql);
        if (la != null)
        {
            kjNo = la.LotteryNo.Split(',');
            week = Week(Convert.ToInt32(la.openTime.DayOfWeek));
            oneCount = la.oneCount.ToString();
            twoCount = la.threeCount.ToString();
            sumMoney = ConvertToMoney(la.sumMoney);
            if (la.openTime != null)
            {
                week = Week(Convert.ToInt32(la.openTime.DayOfWeek));
                kjTime = la.openTime.ToString("yyyy-MM-dd") + week + la.openTime.ToString(" HH:mm");
            }
            // 2015 - 02 - 26(星期四) 21:20 |
        }
        else
        {
            oneCount = "0";
            twoCount = "0";
            sumMoney = ConvertToMoney(0);
            mysumMoney = ConvertToMoney(0);
            mywinMoney = ConvertToMoney(0);
        }
        sql = string.Format("SELECT   sum(onecount) onecount, sum(twocount) twocount, sum(threecount) threecount, sum(fourcount) fourcount, sum(fivecount) fivecount, sum(sixcount) sixcount, sum(sevencount) sevencount, sum(summoney) summoney FROM   LotteryAnnouncementMy WHERE   (LotteryType = {0})  AND (LotteryQs = '{1}')", lotteryType, qs);
        Model.LotteryAnnouncementMy lam = BLL.LotteryAnnouncementMy.NewsTopOne(sql);
        if (lam != null)
        {
            myoneCount = lam.oneCount;
            mythreeCount = lam.threeCount;
        }
        else
        {
            mysumMoney = ConvertToMoney(0);
        }
        sql = string.Format("SELECT  sum(summoney) summoney from LotteryAnnouncementMy  WHERE   (LotteryType = {0})", lotteryType);
        lam = BLL.LotteryAnnouncementMy.NewsTopOne(sql);
        if (lam != null)
        {
            mywinMoney = ConvertToMoney(lam.sumMoney);
        }
    }
    private void bindlotteryTypeName()
    {
        switch (lotteryType)
        {
            case "3":
                lotteryTypeName = "排列三";
                rule1 = "中奖条件：与开奖号相同且顺序一致";
                rule2 = "中奖条件：与开奖号相同，顺序不限";
                break;
            case "5":
                lotteryTypeName = "福彩3D";
                rule1 = "中奖条件：与开奖号相同且顺序一致";
                rule2 = "中奖条件：与开奖号相同，顺序不限";
                break;
            case "4":
                lotteryTypeName = "排列五";
                rule1 = "中奖条件：与开奖号相同且顺序一致";
                break;
        }
    }
    // <summary>
    /// 将数字转换为金额的文字表示方式，最大为千亿最小为分。
    /// </summary>
    /// <param name="d"></param>
    /// <returns></returns>
    private String ConvertToMoney(decimal d)
    {
        string t = "";
        int count = d.ToString().Length;
        if (count > 4 && count < 9)
        {
            if (Convert.ToInt64(d) % 10000 == 0)
            {
                t = "<b class='red'>" + d.ToString().Substring(0, count - 4) + "</b>万";
            }
            else
            {
                t = "<b class='red'>" + d.ToString().Substring(0, count - 4) + "</b>万<b class='red'>" + d.ToString().Substring(count - 4, 4) + "</b>元";
            }
        }
        else if (count >= 9)
        {
            if (Convert.ToInt64(d) % 100000000 == 0)
            {
                t = "<b class='red'>" + d.ToString().Substring(0, count - 8) + "</b>亿";
            }
            else
            {
                t = "<b class='red'>" + d.ToString().Substring(0, count - 8) + "</b>亿<b class='red'>" + d.ToString().Substring(count - 8, 4) + "</b>万<b class='red'>" + d.ToString().Substring(count - 4, 4) + "</b>元";
            }
        }
        else
        {
            t = "<b class='red'>" + d + "</b>元";
        }
        return t;
    }
    private String Week(int d)
    {
        switch (d)
        {
            case 0:
                return "(星期天)";
            case 1:
                return "(星期一)";
            case 2:
                return "(星期二)";
            case 3:
                return "(星期三)";
            case 4:
                return "(星期四)";
            case 5:
                return "(星期五)";
            case 6:
                return "(星期六)";
            default:
                return "";
        }
    }
}